{% extends "base.html" %}
{% block title %}{{ post.title }}{% endblock %}
{% block leftbody %}
<div class="p-4 shadow-sm">
    <div class="row">
        <div class="col">
            <h1>{{ post.title }}</h1>
        </div>
    </div>
    <div class="row shadow-sm">
        <div class="col-lg-6">
            <p>Written By <a href="{{ url_for('blog.posts_by_user', username=post.user.username) }}">{{ post.user.username }}</a> on {{ post.publish_date }}</p>
        </div>
        <div class="col-lg-6">
            <p class="text-right"> Tags: {% for tag in tags %}
                <a href="{{ url_for('blog.posts_by_tag', tag_name=tag.title) }}">{{tag.title}}</a>
                {% endfor %}
            </p>
        </div>
    </div>
    {% if post.youtube_id %}
    <div class="row">
        <div class="col">
            {{ youtube(post.youtube_id) | safe }}
        </div>
    </div>
    {% endif %}
    <div class="row">
        <div class="col">
            {{ post.text | safe }}
        </div>
    </div>
    {% if current_user.id == post.user_id %}
    <div class="col-lg-2">
        <a href="{{ url_for('.edit_post', id=post.id) }}" class="btn
       btn-primary">Edit</a>
    </div>
    {% endif %}
</div>
<div class="p-4 shadow-sm">
    <div class="row">
        <div class="col">
            <h4>New Comment:</h4>
        </div>
    </div>
    <div class="row">
        <div class="col">
            <form method="POST" action="{{ url_for('blog.post', post_id=post.id) }}">
                {{ form.hidden_tag() }}
                <div class="form-group">
                    {{ form.name.label }}
                    {% if form.name.errors %}
                    {% for e in form.name.errors %}
                    <p class="help-block">{{ e }}</p>
                    {% endfor %}
                    {% endif %}
                    {{ form.name(class_='form-control') }}
                </div>
                <div class="form-group">
                    {{ form.text.label }}
                    {% if form.text.errors %}
                    {% for e in form.text.errors %}
                    <p class="help-block">{{ e }}</p>
                    {% endfor %}
                    {% endif %}
                    {{ form.text(class_='form-control') }}
                </div>
                <input class="btn btn-primary" type="submit" value="Add Comment">
            </form>
        </div>
    </div>
</div>
<div class="p-4 shadow-sm">
    <div class="row">
        <div class="col">
            <h4>Comments ({{ comments | length }})</h4>
        </div>
    </div>
    <div class="row p-2">
        <div class="col">
            {% if comments | length == 0 %}
            <p>There are no comments for this post.</p>
            {% else %}
            {% for comment in comments %}
            <div class="shadow-sm p-2">
                <dt>By: {{ comment.name }} on {{ comment.date }}</dt>
                <dd>{{ comment.text }}</dd>
            </div>
            {% endfor %}
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
